package zr.com.thread.tujiejavapattern.ch0102;

public class Gate {
    private int counter = 0;
    private String name = "nobody";
    private String address = "nowhere";

    public synchronized void pass(String name, String address) {
        this.counter++;
        this.name = name;
        this.address = address;
        check();
    }

    private void check() {
        if (this.name.charAt(0) != this.address.charAt(0)) {
            System.out.println(this.name+"==="+this.address);
            System.out.println("*********BROKEN********" + toString());
        }
//        else {
//            System.out.println("*********NORMAL********" + toString());
//        }
    }

    @Override
    public synchronized String toString() {
        return "Gate{" +
                "counter=" + counter +
                ", name='" + name + '\'' +
                ", address='" + address + '\'' +
                '}';
    }
}
